var vueApp = new Vue({
  el: '#app',
  data: function () {
    return {
    	loading: false,    
        currentPageNbr: config.currentPageNbr,
        pageSizes: config.pageSizes,
        pageSize: 6,
        totalRecords: 1,       
        datalist: [],
        objWnd:null,      
        isPic: false,
        showDialog: false,
        media_src:'',
        media_type:'',
        delCount: 0
      };
  },
  computed: {
	  noMore : function () {
		 //this.datalist.length，此长度是每次请求相机数据叠加的，this.scrollbarTotal是后台返回的数据总数
		  return this.datalist.length==0?true:this.datalist.length>= this.totalRecords;
	  },
	  disabled : function () {
		  //scrollDisabled == false,可以滚动
	      return this.loading || this.noMore;
	  }
    },
  mounted: function () {
	  this.load();
  },
  methods: {
   
	      load : function () {	    	  
	         this.loading = true;
             this.onSearch();
          },
	        
	       formatDateTime:function(createdate)
	       {
	    	   return createdate;
	       },
	       
	       onSearch:function(){	    	     
	    	      var that = this;   	    	      
	    	      var jsonStr ={};	 
	    	      jsonStr.title="";
	    	      var postdata = {
	    	            "jsonStr": JSON.stringify(jsonStr),           
	    	            "currentPageNbr" : this.currentPageNbr,
	    	            "pageSize" : this.pageSize
	    	      };

	    	      tools.ajaxRequestAsyncEx("pub/file/uplist",postdata, function(data){
	    	           if (data.respCode == "0"){ //data.list.length>0
	    	        	  console.log(data.list);
	    	        	  let list = data.list;	 
	    	        	
    	        		  for(let i=0; i<list.length; i++){
	    	            	  that.datalist.push(list[i]);
	    	              }
    	        		  that.currentPageNbr += 1;
	    	        	 
	    	              that.totalRecords = data.page.totalRecords;
	    	           }else{
	    	        	   that.showError(data.respDesc);
	    	           }
	    	          
	    	           that.loading = false;
	    	      });


	    	 },
	    	
	    	 showIco:function(item)
		     {
		    	
	    	  if(item.video_url!=""){
	   			return "el-icon-video-play";
	   		  }else{
	   			return "el-icon-picture-outline";
	   		  }		  
	   		
	   		 
	   		 
		     },
		     
	    	 view:function(item)
		     {
		    	
	    	  if(item.video_url==""){
	   			  this.isPic = true;
	   			  this.media_src = "../../"+item.pic_url;
	   		  }else{
	   			  this.isPic = false;
	   			  this.media_src = "../../"+item.video_url;
	   		  }		  
	   		
	   		 
	   		  this.showDialog = true;
		     },
	    	 
	    	 edit:function(item)
		     {
		    	var id="";
	    		 
		    	
		    	if (!item && typeof(item)!="undefined" && item!=0)
		    	{
		    	   
		    	}
		    	else
		    	{
		    		id=item.id;
		    	}
	    		 url="upfile.html?id="+id;
		    	 if(!this.objWnd || this.objWnd.closed)
		    		  this.objWnd = window.open(url);
		    	
		     },
		         
		     del:function(item){
				  var that = this;
				  var reqData = {
					"id":item.id				
				  };
				  tools.ajaxRequestAsyncEx("pub/file/upfileDel", reqData, function(data){
			    	   if (data.respCode == "0") {
			    		
			    		   that.datalist.forEach(function(obj,idx){
				    			 if(obj.id==item.id){
				    				 that.datalist.splice(idx,1);
				    			 } 
				    	   });
			    		   //that.deleted = true;
			    		   that.$message({
			  	 	         showClose: true,
			  	 	         type: 'success',
			  	 	         message: "删除成功"
			  	 	       });			    		  
//			    		   console.log(that.datalist);
			    		   that.totalRecords--;
			    		   that.delCount++;
			    		   if(!that.noMore) {
			    			   that.getDataAfterDel();
			    		   }
			    	   } else {
			    	       that.showError(data.respDesc);      
			    	   }
			      });	  
				  
			  },  
			  //删除之后，补一条数据，这样做可以不破坏查询的逻辑。通过查询接口，还请求当前页的数据，取最后一条记录，就是新的那条数据
			  getDataAfterDel: function() {
				  this.loading = true;
	    	      var that = this;   	    	      
	    	      tools.ajaxRequestAsyncEx("pub/file/uplist",{
	    	            "jsonStr": JSON.stringify({title:""}),           
	    	            "currentPageNbr" : this.currentPageNbr - 1, //因为每次请求后先加了1 所以这里再减1才是当前页
	    	            "pageSize" : this.pageSize
	    	      }, function(data){
	    	           if (data.respCode == "0" && data.list.length > 0){ //data.list.length>0
	    	        	  that.datalist.push(data.list[data.list.length - 1])
	    	              that.totalRecords = data.page.totalRecords;
	    	           }else{
	    	        	   that.showError(data.respDesc);
	    	           }
	    	           that.loading = false;
	    	      });				  
			  },
			  
			  send:function(item){
				  var that = this;
				  var jsonStr = {
							"id": item.id
						  };
				  var reqData ={
					    "jsonStr": JSON.stringify(jsonStr)
					  };
				  tools.ajaxRequestAsyncEx("platServ/dataToSendqueue", reqData, function(data){
			    	   if (data.respCode == "0") {
			    		   that.$message({
			  	 	         showClose: true,
			  	 	         type: 'success',
			  	 	         message: "发送成功"
			  	 	      });
			    		  //location.href="uplist.html";
			    	   } else {
			    	       that.showError(data.respDesc);      
			    	   }
			      });	  
				  
			  }, 
  },
  watch:{
     
  }
  
})